﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Zheng;

namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        string rpath, rhome;


        private void button5_Click(object sender, EventArgs e)
        {
            string confFilePath = @"C:\\Users\\" + Environment.UserName + "\\.rhandler";
            if (!Directory.Exists(confFilePath))
                Directory.CreateDirectory(confFilePath);
            if (rpath != "" && rhome != "")
            {
                File.WriteAllText(confFilePath + "\\config", rpath + "\n" + rhome);
            }
            this.Close();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
        }

        private void button2_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1 = new FolderBrowserDialog();
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                rhome = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            RHandler rh = new RHandler();
            this.Enabled = false;
            rh.loadLibraries();
            MessageBox.Show("libraries loaded, application will be closed, please restart it", "restart me now!");
            Application.Restart();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1 = new FolderBrowserDialog();
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                rpath = folderBrowserDialog1.SelectedPath;
            }
        }
    }
}
